﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Configuration;

public partial class ManRdComment : System.Web.UI.Page
{
    int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["group"] == null)
        {
            Response.Redirect("../Login.aspx");
        }
        else if ((int)Session["group"] != 3)
        {
            Response.Redirect("../Login.aspx");
        }
        if (Request.QueryString.ToString() == "")
        {
            Response.Redirect("ManCommentList.aspx");
        }
        string In;
        string[] CommArray;
        string CommId = "";
        int max = 0;
        id = Int16.Parse(Request.QueryString.ToString());
        SqlConnection sqlcon = null;
        SqlCommand sqlcmd = null;
        SqlCommand sqlcmd2 = null;
        SqlCommand sqlcmd3 = null;
        SqlCommand sqlcmd4 = null;
        SqlDataReader read = null;
        string cmd = "";
        try
        {
            sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
            sqlcon.Open();
            cmd = "select count(*) from notice where tmember='" + Session["uid"] + "' and id='" + id + "'";
            sqlcmd4 = new SqlCommand(cmd, sqlcon);
            read = sqlcmd4.ExecuteReader();
            read.Read();
            In = read.GetValue(0).ToString();
            if (In == "0")
            {
                Response.Redirect("ManCommentList.aspx");
            }
            read.Close();
            cmd = "select member.name,title,[content],time from notice,member where notice.fmember=member.id and notice.id='" + id + "'";
            sqlcmd = new SqlCommand(cmd, sqlcon);
            read = sqlcmd.ExecuteReader();
            read.Read();
            CommTitle.Text = read.GetValue(1).ToString();
            CommFrom.Text = read.GetValue(0).ToString();
            CommText.Text = read.GetValue(2).ToString();
            CommTime.Text = read.GetValue(3).ToString();
            read.Close();
            cmd = "select notice from member where id='" + Session["uid"].ToString() + "'";
            sqlcmd2 = new SqlCommand(cmd, sqlcon);
            read = sqlcmd2.ExecuteReader();
            read.Read();
            CommArray = read.GetValue(0).ToString().Split(';');
            read.Close();
            max = CommArray.Length - 2;
            for (int i = 0; i <= max; i++)
            {
                if (Int16.Parse(CommArray[i]) == id)
                {
                    CommArray[i] = "-1";
                }
            }
            for (int i = 0; i <= max; i++)
            {
                if (CommArray[i] != "-1")
                {
                    CommId = CommId + CommArray[i] + ";";
                }
            }
            cmd = "update member set notice='" + CommId + "' where id='" + Session["uid"] + "'";
            sqlcmd3 = new SqlCommand(cmd, sqlcon);
            sqlcmd3.ExecuteNonQuery();
        }
        catch (SqlException sqle)
        {
            ;
        }
        finally
        {
            sqlcon.Close();
        }
    }
}